package com.yaglyf.mvc.controller.auth;

import com.yaglyf.mvc.aop.annotation.Auth;
import com.yaglyf.mvc.emun.Constant;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Title: Class CommentsShow
 * Description:
 * 负责登入登出 cookies session
 * 数据清理
 *
 * @author qiang.yang
 * @version 1.0.0
 * @email qiang.yang@chinaredstar.com
 * @date: 2016/10/8 17:12
 */
@RestController
public class LoginContrller {

    @RequestMapping(value = "/",method = RequestMethod.GET)
    public ModelAndView loginPage(){
        return new ModelAndView("redirect:login");
    }

    @RequestMapping(value = "login",method = RequestMethod.GET)
    @Auth
    public ModelAndView login(ModelAndView mv){
        mv.setViewName("login");
        boolean flag = true;
       testNum(flag);

        return mv;
    }

    @RequestMapping(value = "index",method = RequestMethod.POST)
    public String index(String username, String password, HttpServletRequest request){
        HttpSession session = request.getSession();
        String pass = (String)session.getAttribute(Constant.J_SESSION.name());




        session.setAttribute(Constant.J_SESSION.name(),null);
        return "user/index";
    }


    private void testNum(boolean b){
        if (b){
            int i = 0;
//            int i1 = 3 / i;
        }
    }
}
